import Vue from '@/main.js';



export function getRoleMenuListByAccount() {
  return Vue.$http.get("/auth/menu/getRoleMenuListByAccount").then((res) => {
    return res.data.data;
  });
}
/**
 * 
 * @param {*} title 
 * @param {*} url 
 * 查询边菜单
 */
export  function getAllMenuList() {
    var path = "/auth/menu/getAllMenuList";
    return Vue.$http.get(path).then((res) => {
        return res.data.data;
    });
}

/**
 * 
 * @param {*} title 
 * @param {*} url 
 * 按照条件查询菜单列表
 */
export  function getMenuList(title, url, pageNum, pageSize) {
    var path = "/auth/menu/getMenuList?";
    path+="title="+title;
    path+="&url="+url;
 
    path+="&pageNum="+pageNum;
    path+="&pageSize="+pageSize;
    return Vue.$http.get(path).then((res) => {
        return res.data.data;
    });
}

/**
 * 
 * @param {*} pid 
 * @param {*} title 
 * @param {*} url
 * @todo 新增菜单
 */
export  function insertMenu(pid, title, url, type, icon, pids) {
    var path = "/auth/menu/insertMenu";
    return Vue.$http.post(path, {
        pid: pid,
        title: title,
        url: url,
        type: type,
        icon: icon,
        pids:pids
      })
      .then((res) => {
          return res;
      })
      .catch(function (error) {
        console.log(error);
      });
             
}

/**
 * 
 * @param {*} pid 
 * @param {*} title 
 * @param {*} url
 * @todo 更新菜单
 */
export  function updateMenu(id, pid, title, url, type, icon,pids) {
    var path = "/auth/menu/updateMenu";
    return Vue.$http.post(path, {
        id: id,
        pid: pid,
        title: title,
        url: url,
        type: type,
        icon: icon,
        pids:pids
      })
      .then((res) => {
          return res;
      })
      .catch(function (error) {
        console.log(error);
      });
             
}


export function menuMoveUp(id) {
  var path = "/auth/menu/menuMove?direction=up&id="+id;
  return Vue.$http.get(path).then((res) => {
    return res;
  });
}
export function menuMoveDown(id) {
  var path = "/auth/menu/menuMove?direction=down&id="+id;
  return Vue.$http.get(path).then((res) => {
    return res;
  });
}


/**
 * @todo 将所有菜单以父级的形式返回
 */

export function getFatherMenuList() {
  var path = "/auth/menu/getFatherFolderList";
  return Vue.$http.get(path).then((res) => {
    return res.data.data;
  });
}




export function ifHasSonMenus(id){
  var path = "/auth/menu/ifHasSonMenus?id="+id;
  return Vue.$http.get(path).then((res) => {
    return res.data;
  });
}

export function deleteMenuById(id){
  var path = "/auth/menu/deleteMenu?id="+id;
  return Vue.$http.get(path).then((res) => {
    return res.data;
  });
}

export function getMenuById(id){
  var path = "/auth/menu/getMenuById?id="+id;
  return Vue.$http.get(path).then((res) => {
    return res.data;
  });
}